package com.ruoyi.project.chopping.controller;

import java.util.List;

import com.ruoyi.project.chopping.domain.BasChopping;
import com.ruoyi.project.chopping.service.IBasChoppingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * choppingController
 * 
 * @author ruoyi
 * @date 2023-06-08
 */
@Controller
@RequestMapping("/system/chopping")
public class BasChoppingController extends BaseController
{
    private String prefix = "/chopping";

    @Autowired
    private IBasChoppingService basChoppingService;

    @GetMapping()
    public String chopping()
    {
        return prefix + "/chopping";
    }

    /**
     * 查询chopping列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasChopping basChopping)
    {
        startPage();
        List<BasChopping> list = basChoppingService.selectBasChoppingList(basChopping);
        return getDataTable(list);
    }

    /**
     * 导出chopping列表
     */
    @Log(title = "chopping", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasChopping basChopping)
    {
        List<BasChopping> list = basChoppingService.selectBasChoppingList(basChopping);
        ExcelUtil<BasChopping> util = new ExcelUtil<BasChopping>(BasChopping.class);
        return util.exportExcel(list, "chopping数据");
    }

    /**
     * 新增chopping
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存chopping
     */
    @Log(title = "chopping", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasChopping basChopping)
    {
        return toAjax(basChoppingService.insertBasChopping(basChopping));
    }

    /**
     * 修改chopping
     */
    @GetMapping("/edit/{stackingId}")
    public String edit(@PathVariable("stackingId") String stackingId, ModelMap mmap)
    {
        BasChopping basChopping = basChoppingService.selectBasChoppingByStackingId(stackingId);
        mmap.put("basChopping", basChopping);
        return prefix + "/edit";
    }

    /**
     * 修改保存chopping
     */
    @Log(title = "chopping", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasChopping basChopping)
    {
        return toAjax(basChoppingService.updateBasChopping(basChopping));
    }

    /**
     * 删除chopping
     */
    @Log(title = "chopping", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basChoppingService.deleteBasChoppingByStackingIds(ids));
    }
}
